package com.sacfa.jframes;

import java.awt.Toolkit;
import java.awt.event.WindowEvent;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import com.sacfa.commons.utilities.Utilities;
import com.sacfa.dialogs.AdministrarTEmail;
import com.sacfa.dialogs.AdministrarTTelefono;
import com.sacfa.dialogs.Registrar;
import com.sacfa.panels.ModificarEmpleado;
import com.sacfa.rrhh.beans.Empleado;

import java.awt.Font;
import javax.swing.JLabel;
import javax.swing.JButton;
import javax.swing.SwingConstants;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

@SuppressWarnings("serial")
public class Extras extends JFrame {
	private JPanel contentPane;
	private static Extras instance = null;
	private ModificarEmpleado modificarEmpleado = null;

	public static Extras getInstance(){
		if(instance == null){
			instance = new Extras();
		}
		return instance;
	}
	
	private Extras() {
		setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
		setSize(507, 277);
		setResizable(false);
		setTitle("Funciones Extra de Administrador");
		setLocationRelativeTo(null);
		setIconImage(Toolkit.getDefaultToolkit().getImage(Utilities.obtenerClassPath() + "resources\\images\\icon.png"));
		addWindowListener(new java.awt.event.WindowAdapter(){
			public void windowClosing(WindowEvent e){
				Utilities.cerrarVentana();
	        }
	    });
		contentPane = new JPanel();
		contentPane.setAutoscrolls(true);
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JLabel lblNewLabel = new JLabel("Agregar un nuevo Usuario >>");
		lblNewLabel.setHorizontalAlignment(SwingConstants.RIGHT);
		lblNewLabel.setFont(new Font("Comic Sans MS", Font.PLAIN, 14));
		lblNewLabel.setBounds(67, 21, 201, 30);
		contentPane.add(lblNewLabel);
		
		JButton btnAgregar = new JButton("Agregar");
		btnAgregar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				new Registrar(null, true).setVisible(true);
			}
		});
		btnAgregar.setBounds(278, 27, 114, 23);
		contentPane.add(btnAgregar);
		
		JButton btnAdministrar = new JButton("Administrar");
		btnAdministrar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				new AdministrarTTelefono(null, true).setVisible(true);
			}
		});
		btnAdministrar.setBounds(278, 78, 114, 23);
		contentPane.add(btnAdministrar);
		
		JLabel lblAdministrarTiposDe = new JLabel("Administrar Tipos de Telefono >>");
		lblAdministrarTiposDe.setHorizontalAlignment(SwingConstants.RIGHT);
		lblAdministrarTiposDe.setFont(new Font("Comic Sans MS", Font.PLAIN, 14));
		lblAdministrarTiposDe.setBounds(33, 72, 235, 30);
		contentPane.add(lblAdministrarTiposDe);
		
		JLabel lblAdministrarTiposDe_1 = new JLabel("Administrar Tipos de Email >>");
		lblAdministrarTiposDe_1.setHorizontalAlignment(SwingConstants.RIGHT);
		lblAdministrarTiposDe_1.setFont(new Font("Comic Sans MS", Font.PLAIN, 14));
		lblAdministrarTiposDe_1.setBounds(33, 127, 235, 30);
		contentPane.add(lblAdministrarTiposDe_1);
		
		JButton button = new JButton("Administrar");
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				new AdministrarTEmail(null, true).setVisible(true);
			}
		});
		button.setBounds(278, 133, 114, 23);
		contentPane.add(button);
		
		JButton btnSalir = new JButton("Salir de Extras");
		btnSalir.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				Principal principal = Principal.getInstance();
				principal.setVisible(true);
				setVisible(false);
			}
		});
		btnSalir.setBounds(173, 199, 125, 23);
		contentPane.add(btnSalir);
		
		paint(getGraphics());
	}
	
	public void modificar(Empleado empleado){
		modificarEmpleado = new ModificarEmpleado(empleado);
		setSize(modificarEmpleado.getWidth(), modificarEmpleado.getHeight());
		contentPane.add(modificarEmpleado);
		paint(getGraphics());
	}
}
